package com.briup.app02.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.app02.bean.Comment;
import com.briup.app02.bean.CommentExample;
import com.briup.app02.dao.CommentMapper;
import com.briup.app02.service.ICommentService;
import com.briup.app02.utils.CustomerException;

@Service
public class CommentServiceImpl implements ICommentService {

	@Autowired
	private CommentMapper commentMapper;
	@Override
	public void deleteById(Long id) throws CustomerException {
		// TODO Auto-generated method stub
		Comment comment = commentMapper.selectByPrimaryKey(id);
		if(comment==null) {
			throw new CustomerException("要删除的评论不存在");
		}
		commentMapper.deleteByPrimaryKey(id);
}

	@Override
	public void saveOrUpdate(Comment comment) {
		// TODO Auto-generated method stub
		if(comment.getId()!=null) {
			commentMapper.updateByPrimaryKey(comment);
		}else {
			commentMapper.insert(comment);
		}
		
	}

	@Override
	public void batchDelete(List<Long> id) {
		CommentExample example = new CommentExample();
		example.createCriteria().andIdIn(id);
		commentMapper.deleteByExample(example);
		
	}

	
	@Override
	public List<Comment> query(String comment,String status) {
		CommentExample example = new CommentExample();
		if(comment!=null) {
			example.createCriteria().andCommentLike("%"+comment+"%");
		
	}
		if(status!=null){
			example.createCriteria().andStatusEqualTo(status);
		}
		List<Comment> list = commentMapper.selectByExample(example);
		return list;
}	
	@Override
	public void check(Long id, String status) {
		// TODO Auto-generated method stub
		Comment comment = commentMapper.selectByPrimaryKey(id);
		comment.setStatus(status);
		commentMapper.updateByPrimaryKey(comment);
	}




	


}
